package oop.java0408;

/**
 * 遥控器类有重量，无线范围，颜色等属性
 * 有控制电视开机、关机、换台等功能
 */
public class Remote {
    private double weight;
    private int range;//无线范围
    private String color;

    public Remote() {
    }

    public Remote(double weight, int range, String color) {
        setWeight(weight);
        setRange(range);
        this.color = color;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        if (weight < 0) {
            throw new RuntimeException("遥控器重量不能为负数");
        }
        this.weight = weight;
    }

    public int getRange() {
        return range;
    }

    public void setRange(int range) {
        if (range < 0) {
            throw new RuntimeException("无线范围不能为负数");
        }
        this.range = range;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public void controlTurnOn(TV tv) {
        System.out.println("使用遥控器打开电视机");
        tv.turnOn();

    }

    public void controlTurnOff(TV tv ) {
        System.out.println("使用遥控器关闭电视机");
        tv.turnOff();
    }

    public void controlExchange(TV tv,String newChannel) {
        System.out.println("使用遥控器换台");
        tv.exchange(newChannel);
    }

    @Override
    public String toString() {
        return "遥控器信息：\n重量" + weight + "克，遥控范围" + range + "米，颜色" + color;
    }
}
